package com.ly.common.core.tool.security.config;

import com.ly.common.core.tool.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Set;

/**
 * 权限判断-按钮 识别 @PreAuthorize("@ss.hasPermission('system:permission:add')")
 */
@Service(value = "ss")
public class AuthorityConfig {

    /**
     * 判断接口是否有权限
     * @param permissions 权限
     * @return /
     */
    public Boolean hasPermission(String ...permissions){
        // 获取当前用户的所有权限
        Set<String> list = SecurityUtils.getButtonAuth();
        // 判断当前用户的所有权限是否包含接口上定义的权限
        return list!=null && (list.contains("admin") || Arrays.stream(permissions).anyMatch(list::contains));
    }
}
